local serviceId
local conns = {}

function OnInit(id)
    print("[lua] chat OnInit id : " .. id)
    serviceId = id 
    sunnet.Listen(7772, id)
end 

function OnAcceptMsg(listenfd, clientfd)
    conns[clientfd] = true
end

function OnServiceMsg(toSrv, msg)
    print("[lua] chat OnServiceMsg")

end 

function OnSocketData(fd, msg) 
    print("[lua] chat OnSocketData fd : " .. fd)
    for fd, _ in pairs(conns) do 
        sunnet.Write(fd, msg)
    end 
end

function OnSocketClose(fd)
    print("[lua] chat OnSocketClose fd : " .. fd)
    conns[fd] = false
end

function OnExit() 
    print("[lua] chat OnExit")
end 